<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\MettingActivity
 *
 * @property int $id 主键
 * @property string|null $title 活动名称
 * @property string $image 图片
 * @property int $num 人数限制
 * @property string|null $closing_at 截止日期
 * @property string|null $content 活动介绍
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\MeetingActivityEnroll[] $enrolls
 * @property-read int|null $enrolls_count
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingActivity newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingActivity newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingActivity query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingActivity whereClosingAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingActivity whereContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingActivity whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingActivity whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingActivity whereImage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingActivity whereNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingActivity whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MeetingActivity whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class MeetingActivity extends Model
{
    protected $table = 'meeting_activity';
    protected $primaryKey = 'id';
    protected $fillable = ['title', 'image', 'num', 'closing_at', 'content'];

    /**
     * @param $value
     * @return string
     */
    public function getImageAttribute($value)
    {
        return $value ? image_url($value) : $value;
    }

    /**
     * @param $value
     */
    public function setImageAttribute($value)
    {
        $this->attributes['image'] = strip_image_url($value);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function enrolls()
    {
        return $this->hasMany(MeetingActivityEnroll::class, 'activity_id', 'id');
    }
}
